<style lang="less">
@import '../../../assets/style/celiang.less';
</style>

<template>
	<mxq-router-layout>
		<div class="celiang">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					<span>测量记录</span>
				</div>
				<div slot="headerRight">
					<i class="iconfont icon-shouye"/>
					<!--<van-icon class="home" name="home"/>-->
				</div>
			</Head>
			<van-cell-group>
				<van-cell title="接地电阻测量" class="tit"/>
				<van-field
					v-model="formItem.numberA"
					type="number"
					label="A"
					placeholder="请输入"/>
				<van-field
					v-model="formItem.numberB"
					type="number"
					label="B"
					placeholder="请输入"/>
				<van-field
					v-model="formItem.numberC"
					type="number"
					label="C"
					placeholder="请输入"/>
				<van-field
					v-model="formItem.numberD"
					type="number"
					label="D"
					placeholder="请输入"/>
				<p class="cl_text" @click="echoMeasure1()">历史测量记录</p>
			</van-cell-group>
			<!--接地电阻测量历史记录弹出框-->
			<van-popup v-model="first" style="width:80%" >
				<div v-for="item in echoData1">
					<div class="box" v-if="echoData1.length>0 && (item.A!=null || item.B!=null || item.C!=null || item.D!=null)">
						<van-cell title="接地电阻测量" class="tit"/>
						<van-field
						style="width:100%"
						v-model="item.CREATE_TIME"
						label="创建时间:"
						disabled
						placeholder="无"/>
						<van-field
							v-model="item.A"
							type="number"
							label="A:"
							disabled
							placeholder="无"/>
						<van-field
							v-model="item.B"
							type="number"
							label="B:"
							disabled
							placeholder="无"/>
						<van-field
							v-model="item.C"
							type="number"
							label="C:"
							disabled
							placeholder="无"/>
						<van-field
							v-model="item.D"
							type="number"
							label="D:"
							disabled
							placeholder="无"/>
					</div>
				</div>
				<div v-model="first" v-if="echoData1.length==0 || (echoData1.length>0 && dataA==null && dataB==null && dataC==null && dataD==null)">
					<van-cell title="暂无数据" style="text-align: center;"/>
				</div>
			</van-popup>
			<van-cell-group>
				<van-cell title="交叉跨越测量" class="tit"/>
				<van-field
					id="area"
					v-model="formItem.message"
					type="textarea"
					placeholder="请输入"
					rows="5"
					autosize/>
				<p class="cl_text" @click="echoMeasure2()">历史测量记录</p>
			</van-cell-group>
			<!--交叉跨越测量历史记录弹出框-->
			<van-popup v-model="second" style="width:80%" >
				<div  v-for="item in echoData2">
					<div class="jxmodal" v-if="echoData2.length>0 && item.OVERLAPPING!=null">
						<van-cell title="交叉跨越测量" class="tit"/>
						<van-field
						style="width:100%"
							v-model="item.OVERLAPPING"
							type="textarea"
							placeholder="无"
							rows="2"
							disabled
							autosize/>
						<van-field
							v-model="item.CREATE_TIME"
							label="创建时间:"
							disabled
							placeholder="无"/>
					</div>
				</div>
				<div v-model="second" v-if="echoData2.length==0 || (echoData2.length>0 && overlapping ==null)">
					<van-cell title="暂无数据" style="text-align: center;"/>
				</div>
			</van-popup>
			<van-button v-if="$route.query.gantaStatus!=2" size="large" type="primary" @click="upLoad">上传测量记录</van-button>
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '../../../components/head';
import { callData } from '../../../axios/axios'
import {
    Cell,
    CellGroup,
    Field,
    Icon,
    Button,
    Popup,
    Toast
} from 'vant';

export default {
    name: 'xljx_ceLiang',
    components: {
        Head,
        [Cell.name]: Cell,
        [CellGroup.name]: CellGroup,
        [Field.name]: Field,
        [Icon.name]: Icon,
        [Button.name]: Button,
        [Popup.name]: Popup,
        [Toast.name]: Toast
    },
    data() {
        return {
        	first:false,
        	second:false,
        	echoData:{},
        	echoData1:[],
        	dataA:'',
        	dataB:'',
        	dataC:'',
        	dataD:'',
        	echoData2:[],
        	overlapping:'',
        	formItem:{
        		numberA: "",
	            numberB: "",
	            numberC: "",
	            numberD: "",
	            message: ""
        	}
        }
    },
    mounted(){
    	this.echoMeasure();
    },
    methods: {
		headerClick(e){
            let query = {}
			this.$router.push({
				name:'index',
				query: query
			})
       	},
        //上传
        upLoad() {
        	let params = {
        		a:this.formItem.numberA,
        		b:this.formItem.numberB,
        		c:this.formItem.numberC,
        		d:this.formItem.numberD,
        		overlapping:this.formItem.message,//交叉跨越测量
        		towerId:this.$route.query.towerId,//物理杆塔id
        		lineTowerId:this.$route.query.lineTowerId,//逻辑杆塔id
        		taskId:this.$route.query.taskId,//任务id
        		towerTaskId:this.$route.query.towerTaskId//杆塔任务id
        	};
        	//修改
        	if (this.formItem.id) {
        		params['id'] = this.formItem.id
        	}
           callData('/accountServer/CmMeasure/appAddMeasure', 'post', params).then(res => {
        		if(res.success){
                    Toast(res.data)
                    this.$router.go(-1)
               }else{
                	Toast(res.data)
                }
			})
        },
        echoMeasure(){//回显
        	callData('/accountServer/CmMeasure/appFindMeasure', 'get', {
        		towerId:this.$route.query.towerId,//物理杆塔id
        		lineTowerId:this.$route.query.lineTowerId,//逻辑杆塔id
        		taskId:this.$route.query.taskId,//任务id
        		towerTaskId:this.$route.query.towerTaskId//杆塔任务id
        	}).then(res => {
        		var echoData = res.data[0];
        		if(echoData){
        			this.formItem.id = echoData.ID;
        			this.formItem.numberA = echoData.A;
	        		this.formItem.numberB = echoData.B;
	        		this.formItem.numberC = echoData.C;
	        		this.formItem.numberD = echoData.D;
	        		this.formItem.message = echoData.OVERLAPPING;
	        		this.formItem.time = echoData.CREATE_TIME;
        		} 
			})
        },
        echoMeasure1(){//历史记录1
        	this.first=true;
        	callData('/accountServer/CmMeasure/appFindMeasure', 'get', {
        		towerId:this.$route.query.towerId,//物理杆塔id
        		lineTowerId:this.$route.query.lineTowerId,//逻辑杆塔id
        		//taskId:this.$route.query.taskId,//任务id
        		//towerTaskId:this.$route.query.towerTaskId//杆塔任务id
        	}).then(res => {
        		this.echoData1 = res.data;
        		if(this.echoData1.length>0){
        			this.echoData1.forEach(v=>{
	        			this.dataA = v.A
	        			this.dataB = v.B
	        			this.dataC = v.C
	        			this.dataD = v.D
	        		})
        		}
			})
        },
        echoMeasure2(){//历史记录2
        	this.second=true;
        	callData('/accountServer/CmMeasure/appFindMeasure', 'get', {
        		towerId:this.$route.query.towerId,//物理杆塔id
        		lineTowerId:this.$route.query.lineTowerId,//逻辑杆塔id
        		//taskId:this.$route.query.taskId,//任务id
        		//towerTaskId:this.$route.query.towerTaskId//杆塔任务id
        	}).then(res => {
        		this.echoData2 = res.data;
        		if(this.echoData2.length>0){
        			this.echoData2.forEach(v=>{
	        			this.overlapping = v.OVERLAPPING
	        		})
        		}
			})
        }
    }
}
</script>
